/*
 * @Author: malgee
 * @Date: 2025-04-23 15:38:03
 * @LastEditors: maling
 * @LastEditTime: 2025-04-27 17:03:49
 * @FilePath: /vue3-ts-cms/src/mock/index.ts
 * @Description: 模拟数据
 * 
 */
import { MGRequestConfig, MGDataType } from '@/service/request/type'
import LoginMock from './login/login'

enum MockPath {
  LOGIN = '/login',  // 登录
  USER_INFO = '/user/:id',  // 用户信息
  USER_LIST = '/user/list',  // 用户列表
  ROLE_MENUS = '/role/:id/menus',  // 用户菜单
  ROLE_LIST = '/role/list',  // 角色列表
  DEPARTMENT_LIST = '/department/list',  // 部门列表
  MENU_LIST = '/menu/list'  // 菜单列表
}

export class MockHttp {
  getData<T = any>(config: MGRequestConfig): Promise<T> {
    console.log('mock data-config', config);
    const url = config.url

    // Extract numbers from URL if it contains any
    const matches = url?.match(/\d+/g);
    const numericId = matches ? matches[0] : null;

    return new Promise((resolve) => {
      setTimeout(() => {
        switch (config.url) {
          case MockPath.LOGIN:
            resolve(LoginMock.loginData() as T)
            break;
          case MockPath.USER_INFO.replace(':id', numericId?.toString() || ''):
            resolve(LoginMock.userInfo() as T)
            break;
          case MockPath.USER_LIST:
            resolve(LoginMock.userList() as T)
            break;
          case MockPath.ROLE_MENUS.replace(':id', numericId?.toString() || ''):
            resolve(LoginMock.userMenus() as T)
            break;
          case MockPath.ROLE_LIST:
            resolve(LoginMock.roleList() as T)
            break;
          case MockPath.DEPARTMENT_LIST:
            resolve(LoginMock.departmentList() as T)
            break;
          case MockPath.MENU_LIST:
            resolve(LoginMock.menuList() as T)
            break;
          default:
            resolve('mock data' as T)
            break;
        }
      }, 250)
    })
  }
}

export const mockHttp = new MockHttp()

export const isMock = true